<template>
    <div>
      <el-upload
        class="upload"
        :action="uploadUrl"
        drag
        :with-credentials="true"
        accept="application/vnd.ms-excel"
        :on-success="uploadSuccess"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传,将自动导入</em></div>
        <div class="el-upload__tip" slot="tip">只能上传excel2003-2007文件</div>
      </el-upload>
      <p>
        <el-button type="primary" @click="downloadTemplate"><i class="el-icon-download"></i>下载模板</el-button>
      </p>
    </div>
</template>

<script>
import api from '@/api'
export default {
  data () {
    return {
      uploadUrl: api.baseURL + '/questions/excel'
    }
  },
  methods: {
    downloadTemplate () {
      window.location.href = `${api.baseURL}/questions/template`
    },
    uploadSuccess (resp) {
      let __this = this
      this.$message('导入成功')
      setTimeout(function () {
        __this.$router.push({ name: 'testQues' })
      }, 500)
    }
  }
}
</script>

<style scoped lang="less">
  .upload{
    margin-top: 100px;
  }
</style>
